﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Globalization;
using SimpleTool.Server;
using System.Windows.Controls;
using System.Windows.Documents;
using Serilog.Core;
using Serilog;
using System.Windows;

namespace SimpleTool.Server
{
    public class CommonCoverter : IMultiValueConverter
    {

        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            string object_name = string.Empty;
            object[] objects;
            if (values.Length < 2)
            {
                throw new ArgumentException("binding count error");
            }
            else
            {
                if (values[0] != null) object_name = values[0].GetSafetyChar();
                objects = [.. values.ToList().GetRange(1, values.Length - 1)];
            }
            return new MultiCommonInfos(object_name, objects);
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    public class RichTextBoxGetValueCoverter : IValueConverter
    {
        public ILogger Logger = Log.ForContext<RichTextBoxGetValueCoverter>();
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            
            if (value is RichTextBox textbox)
            {
                TextPointer start = textbox.Document.ContentStart;
                TextPointer end = textbox.Document.ContentEnd;
                TextRange getRange = new (start, end);
                return getRange.Text;
            }
            return string.Empty;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    public class GridDefinAttributeConvert : IValueConverter
    {
        public readonly static ILogger Logger = Log.ForContext<GridDefinAttributeConvert>();
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {

            if (value is Visibility visible)
            {
                switch (visible)
                {
                    case Visibility.Collapsed:

                        return GridLength.Auto;

                    case Visibility.Visible:

                        return new GridLength(1, GridUnitType.Star);
                }
                Logger.DebudElite(targetType, visible);
            }
            return GridLength.Auto;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

}
